/* 注册 */
require("../css/register.less")

const CaptchaMini = require("../lib/captcha-mini.js")
//文档加载完毕
document.ready(function () {
   /*不传值，统一走默认值*/
   let captcha1 = new CaptchaMini();
   let mood=""
   captcha1.draw(document.querySelector('#captcha1'), r => {
       mood=r
       console.log(r, '验证码1');
   });

   let phonInp=document.querySelector("#phonInp")
   let verInt=document.querySelector("#verInt")
   let pasitInt=document.querySelector("#pasitInt")
   let pasAgin=document.querySelector("#pasAgin")
   let btn=document.querySelector("#btn")
   let tishi=document.querySelector(".tishi")

   let PasTLogin=document.querySelector("#PasTLogin") 
   PasTLogin.onclick=function(){
       window.location.href="./login.html"
   }

   //注册按钮
   btn.addEventListener("click",function(){
        //获取手机号
        let phone=phonInp.value
        //获取验证码
        let verFcaTion=verInt.value
        //获取密码
        let pass=pasitInt.value
        //获取再次输入的密码
        let passAgin=pasAgin.value
        
        
    if(!window.$utils.isphone(phone)){
        tishi.textContent="号码错误"
    }else if(!mood==verFcaTion){
        tishi.textContent="验证码有误"
    }else if(!window.$utils.ispassword(pass)){      
        tishi.textContent="密码格式不正确"
    }else if(!pass==passAgin){
        tishi.textContent="两次密码不一样"
    }else{
        console.log("发送ajax请求");
        axios.post("http://139.9.177.51:8099/users/add",{
            "account":phone,
            "password":pass
        })
        .then(function(res){
            console.log(res);
            let resdata=res.data
            console.log(resdata.msg);
            if(resdata.status===0){
               
                // tishi.textContent="恭喜注册成功"
                window.location="./login.html"
            }else if(resdata.status===5001){
                
                tishi.textContent="注册失败"
            }
        })
        .catch(function(error){
            
        })
        //ajax 验证
        // window.location.href=""
    }




   })

})
